<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="btn">点我</div>
</body>
<script>


    class Star {
        constructor(val){
            this.name = val
            console.log(this); ///this  指向实例化出来的对象
            // 获取dom节点
            let btn = document.querySelector('.btn')
            // 给btn注册一个点击事件
            btn.onclick = this.fn.bind(this)

        }
         fn(){
            console.log(this)
            alert(this.name)

         }
        // fn=()=>{
        //     console.log(this);//
        //     console.log('我是fn');
        //     alert(this.name)
        // }
    }
   let s = new Star('任春旭')
   console.log(s);
</script>
</html>